<%@ page import="com.uni.entity.User" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  <title>闲优购-</title>

  <link rel="icon" href="img/weblogo.png" >
  <link rel="stylesheet" type="text/css" href="bootstrap-5.1.3-dist/css/bootstrap.min.css"/>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css">
  <link rel="stylesheet" type="text/css" href="css/ycc.css"/>
  <script type="text/javascript" src="js/jquery-3.6.0-min.js"></script>
  <script type="text/javascript" src="bootstrap-5.1.3-dist/js/bootstrap.min.js"></script>
  <script type="text/javascript" src="js/card_user_buy_record.js"></script>
<body>
<div style="margin-inline: auto">
  <h5>当前位置:商品管理>>管理商品</h5>
</div>

<div style="float: right;">

</div>
<table class="table table-striped">
  <thead>
  <tr>
    <th>商品编号</th>
    <th>商家编号</th>
    <th>商家名称</th>
    <th>商品名称</th>
    <th>商品类型</th>
    <th>商品价格</th>
    <th>操作</th>
  </tr>
  </thead>
  <tbody>
  <c:forEach items="${sessionScope.commodityList}" begin="${sessionScope.adminCommoityPage.pageNow}" end="${sessionScope.adminCommoityPage.pageNow + 5}" var="ct">
    <c:if test="${not empty ct}">
      <tr>
        <td>${ct.id}</td>
        <td>${ct.uid}</td>
        <td>${ct.userName}</td>
        <td>${ct.name}</td>
        <td>${ct.typeName}</td>
        <td>${ct.price}</td>
        <td>
          <button class="btn btn-danger btn-delete-user" data-href="/adminDeleteCommoidty?id=${ct.id}">删除</button>
        </td>
      </tr>
    </c:if>
  </c:forEach>
  </tbody>
</table>

<c:if test="${not empty sessionScope.adminCommoityPage}">
  <c:set value="${sessionScope.adminCommoityPage}" var="page"/>
  <nav aria-label="Page navigation">
    共${page.totalRows} 条记录, ${page.pageNow} / ${page.totalPage}
    <ul class="pagination">
      <li class="page-item"><a class="page-link" href="/adminSelectAllCommodityPageable?page=${page.pageNow - 1}">上一页</a></li>
      <li class="page-item" style="margin-left: auto;"><a class="page-link" href="/adminSelectAllCommodityPageable?page=${page.pageNow + 1}">下一页</a></li>
    </ul>
  </nav>
</c:if>
</body>
<script>
  $(document).ready(function(){
    $(".btn-delete-user").click(function (){
      var hf = $(this).data('href')
      $.ajax({
        url: hf,
        type: 'GET',
        async: false,
        error: function (){
          alert('AJAX请求错误')
        },
        success: function (res){
          if (res == "true")
            alert('删除成功!')
          else
            alert('删除失败.')
          window.location.href='adminSelectAllCommodityPageable'
        }
      })

    });

  });
</script>
</html>
